<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
  <style type="text/css">
  .layui-form-select .layui-input {
      padding-right: 30px;
      cursor: pointer;
      width: 400px;
  }
  </style>
</head>
<body class="patch_body">
<div class="tplay-body-div">
    <div class="layui-tab">
      <ul class="layui-tab-title">
        <li ><a href="{:url('admin/nav/index')}" class="a_menu">导航列表</a></li>
        <li class="layui-this">新增导航</li>
      </ul>
    </div> 

    <form class="layui-form" id="admin">

      <div class="layui-form-item">
        <label class="layui-form-label">导航名称</label>
        <div class="layui-input-block" style="max-width:400px;">
          <input name="nav_name" autocomplete="off" placeholder="请输入导航名称" class="layui-input" type="text" lay-verify="required" {notempty name="$info.nav_name"}value="{$info.nav_name}"{/notempty}>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">链接地址</label>
        <div class="layui-input-block" style="max-width:400px;">
          <input name="path_url" autocomplete="off" placeholder="请输入链接地址" class="layui-input" type="text" lay-verify="url" {notempty name="$info.path_url"}value="{$info.path_url}"{/notempty}>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">复选框</label>
        <div class="layui-input-block">
          <input type="radio" lay-filter="erweima" name="type" value="1" title="主导航" {notempty name="$info.type"}{if $info.type eq 1}checked=""{/if}{else}checked=""{/notempty} >
          <input type="radio" lay-filter="erweima" name="type" value="2" title="顶部" {notempty name="$info.type"}{if $info.type eq 2}checked=""{/if}{else}{/notempty} >
          <input type="radio" lay-filter="erweima" name="type" value="3" title="底部" {notempty name="$info.type"}{if $info.type eq 3}checked=""{/if}{else}{/notempty} >
        </div>
      </div>

      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">上级分类</label>
        <div class="layui-input-inline" style="max-width:600px;">
             <select name="pid" lay-filter="aihao" id="pid">
                 <option value="0">顶级分类</option>
                {notempty name="cates"}
                {volist name="$cates" id="vo"}
                <option value="{$vo.id}" {notempty name="$info.pid"}{eq name="$info.pid" value="$vo.id"} selected=""{/eq}{/notempty}>{$vo.str}{$vo.nav_name}</option>
                {/volist}
                {/notempty}
              </select>
        </div>
        <div class="layui-form-mid layui-word-aux">分类只支持三级<span style="color: red">*如果是修改一定要选择顶级分类</span></div>
      </div>



      <div class="layui-form-item">
        <label class="layui-form-label">新窗口打开</label>
        <div class="layui-input-block">
          <input type="radio" lay-filter="erweima" name="target" value="1" title="开启" {notempty name="$info.target"}{if $info.target eq 1}checked=""{/if}{else}checked=""{/notempty} >
          <input type="radio" lay-filter="erweima" name="target" value="2" title="关闭" {notempty name="$info.target"}{if $info.target eq 2}checked=""{/if}{else}{/notempty} >
        </div>
      </div>

          
      <div class="layui-form-item">
        <label class="layui-form-label">备用标签</label>
        <div class="layui-input-block" style="max-width:400px;">
          <input name="tag" autocomplete="off" placeholder="请输入备用标签" class="layui-input" type="text" {notempty name="$info.tag"} value="{$info.tag}" {/notempty}>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block" style="max-width:400px;">
          <input name="sort" autocomplete="off" placeholder="请输入排序" class="layui-input" type="text" lay-verify="number" {notempty name="$info.sort"} value="{$info.sort}" {/notempty}>
        </div>
      </div>

    <!--   <div class="layui-upload" id="upload-thumb">
        <label class="layui-form-label">缩略图</label>
        <button type="button" class="layui-btn" id="thumb">上传图片</button>
        <div class="layui-upload-list">
          <label class="layui-form-label"></label>
          <img class="layui-upload-img" id="demo1" width="150" height="150" {notempty name="$info.thumb"}src="{$info.thumb|geturl}"{/notempty}>{notempty name="$info.thumb"}<input type="hidden" name="thumb" value="{$info.thumb}">{/notempty}
          <p id="demoText"></p>
        </div>
      </div> -->

      {notempty name="$info"}
      <input type="hidden" name="id" value="{$info.id}">
      {/notempty}

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>

    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>

    <!-- <script>
        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
    </script> -->
    <script>
    layui.use('upload', function(){
      var upload = layui.upload;
      //执行实例
      var uploadInst = upload.render({
        elem: '#thumb' //绑定元素
        ,url: "{:url('common/upload')}" //上传接口
        ,data:{use:'link_thumb'}
        ,done: function(res){
          //上传完毕回调
          if(res.code == 2) {
            $('#demo1').attr('src',res.src);
            $('#upload-thumb').append('<input type="hidden" name="thumb" value="'+ res.id +'">');
          } else {
            layer.msg(res.msg);
          }
        }
        ,error: function(){
          //请求异常回调
          //演示失败状态，并实现重传
          var demoText = $('#demoText');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function(){
            uploadInst.upload();
          });
        }
      });
    });
    </script>
    <script>
      layui.use(['layer', 'form'], function() {
          var layer = layui.layer,
              $ = layui.jquery,
              form = layui.form;
          $(window).on('load', function() {
              form.on('submit(admin)', function(data) {
                  $.ajax({
                      url:"{:url('admin/nav/publish')}",
                      data:$('#admin').serialize(),
                      type:'post',
                      async: false,
                      dateTyoe:"json",
                      success:function(res) {
                          if(res.code == 1) {
                              layer.alert(res.msg, function(index){
                                location.href = res.url;
                              })
                          } else {
                              layer.msg(res.msg);
                          }
                      }
                  })
                  return false;
              });
          });
      });
    </script>
</div>
</body>
</html>